<?php
$arguements = $_SERVER['argv'];

$keylock = $arguements[2];
$length = $arguements[1];

//Wait bot
include_once("SmartIRC.php");

function writepid()
{
	$PIDFile = "wait.pid";
	$fh = fopen($PIDFile, 'w') or die("can't open file");
	$stringData = getmypid();
	fwrite($fh, $stringData);
	fclose($fh);
}

class PickupBot
{
	function wait(&$irc, &$data)
	{
	    global $keylock;
	    global $length;
		//$irc->message(SMARTIRC_TYPE_QUERY, "PixelTF2Bot", $keylock);
		echo "\n\n".$length."\n\n";
		echo "\n\n".$keylock."\n\n";
		//$irc->message(SMARTIRC_TYPE_QUERY, $irc->_nick, "cocobeans");
		$irc->message(SMARTIRC_TYPE_CHANNEL, "#pixeltf2.admin", "1\n2\n3\n");
		sleep($length);
	}

	function kill(&$irc, &$data)
	{
		$irc->disconnect();
		die();
	}
	
	function leave(&$irc, &$data)
	{
		print_r($data);
		$irc->whois($data->nick);
	}
	
	function quit(&$irc, &$data)
	{
		print_r($data);
	}
	
	function kick(&$irc, &$data)
	{
		print_r($data);
	}
	
	function whois(&$irc, &$data)
	{
		if($data->rawmessageex[1] == "330")
		{
			print_r($data);
		}
	}
}

$PickupBot = &new PickupBot;

//Create bot class
$irc = &new Net_SmartIRC();

//Set info
$irc->setUseSockets(true);

//Enable debugging
$irc->setDebug(SMARTIRC_DEBUG_IRCMESSAGES);

writepid();

//Connect Bot
	$irc->connect('multiplay.uk.quakenet.org', 6667);
	$irc->login('Testbot', 'PixelGaming.eu Pickup Bot #2', 0,'PixelWaitBot');
	$irc->join('#pixeltf2.admin', 'dreamworks');

//$irc->registerActionhandler(SMARTIRC_TYPE_JOIN, '', &$PickupBot, 'wait');
$irc->registerActionhandler(SMARTIRC_TYPE_QUERY, 'cocobeans', &$PickupBot, 'kill');
$irc->registerActionhandler(SMARTIRC_TYPE_PART, '', &$PickupBot, 'leave');
$irc->registerActionhandler(SMARTIRC_TYPE_QUIT, '', &$PickupBot, 'quit');
$irc->registerActionhandler(SMARTIRC_TYPE_KICK, '', &$PickupBot, 'kick');
$irc->registerActionhandler(SMARTIRC_TYPE_UNKNOWN, '', &$PickupBot, 'whois');

$irc->listen();


$irc->disconnect();

?>
